//
//  PublicDefine.h
//  XingXue
//
//  Created by XingXue on 2023.
//  Copyright © 2023 XingXue. All rights reserved.
//

#ifndef PublicDefine_h
#define PublicDefine_h

//颜色
#define Color(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

#define INT2NUM(x) [NSNumber numberWithInt:x]

#define CusNotificationHadHandleFileSuccess @"CusNotificationHadHandleFileSuccess"
#define CusNotificationHadAddFile @"CusNotificationHadAddFile"
#define ScreenWidthWS  [UIScreen mainScreen].bounds.size.width
#define ScreenHeightWS  [UIScreen mainScreen].bounds.size.height
#define ScreenScale (ScreenWidthWS/375.0)
#define ScreenHeightScale  (ScreenHeightWS/812.0)
#define ScreenFontScale  ((ScreenWidthWS <= 375) ? (ScreenWidthWS/375.0):1.0)

#define WeakObj_Cus(o) autoreleasepool{} __weak typeof(o) o##Weak = o;
#define StrongObj_Cus(o) autoreleasepool{} __strong typeof(o) o = o##Weak;

#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define kNavBarHeight 44.0
//注意：请直接获取系统的tabbar高度，若没有用系统tabbar，建议判断屏幕高度；之前判断  状态栏高度的方法不妥，如果正在通话状态栏会变高，导致判断异常，下面只是一个例子，请勿直接使用！
#define kTopHeight (kStatusBarHeight + kNavBarHeight)

#define kBottomSafeAreaHeight (KIsiPhoneX ? 34.f : 0.f)

//程序的本地化,引用国际化的文件
#define MyLocal(x, ...) NSLocalizedString(x, nil)

//返回安全的字符串
#define kSafeString(str) [str isKindOfClass:[NSString class]] > 0 ? str : @""

//屏幕 rect
#define SCREEN_RECT ([UIScreen mainScreen].bounds)

#define CONTENT_HEIGHT (kScreenHeight - NAVIGATION_BAR_HEIGHT - STATUS_BAR_HEIGHT)

//屏幕分辨率
#define SCREEN_RESOLUTION (kScreenWidth * kScreenHeight * ([UIScreen mainScreen].scale))

#define kScreenWidth ([UIScreen mainScreen].bounds.size.width)
#define kScreenHeight ([[UIScreen mainScreen] bounds].size.height)

// 以iphone6为参考 宽高的缩放比
#define kWidthScale (kScreenWidth / 375.f)
#define kHeightScale (kScreenHeight / 667.f)
#define kAdaptWidth(width) (kWidthScale * width)
#define kAdaptHeight(height) (kHeightScale * height)

//单例宏
#define SINGLETON_INTERFACE(className) +(className*)sharedInstance

#define UIColorWithHex(hexValue) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0 \
green:((float)((hexValue & 0xFF00) >> 8))/255.0 \
blue:((float)(hexValue & 0xFF))/255.0 alpha:1]

#define UIColorWithHexAlpha(rgbValue, alp)                                  \
[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0       \
green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0          \
blue:((float)(rgbValue & 0xFF)) / 255.0                   \
alpha:alp]

#define UIColorFromHexA(hexValue, a)     [UIColor colorWithRed:(((hexValue & 0xFF0000) >> 16))/255.0f green:(((hexValue & 0xFF00) >> 8))/255.0f blue:((hexValue & 0xFF))/255.0f alpha:a]
#define UIColorFromHex(hexValue)        UIColorFromHexA(hexValue, 1.0f)
#define UIColorFrom255RGBA(r, g, b, a)  ([UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a])
#define UIColorFrom255RGB(r, g, b)      UIColorFrom255RGBA(r,g,b,1.0f)

//是不是iphone5
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
#define IS_IPHONE_6 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )667 ) < DBL_EPSILON )
#define IS_IPHONE_7 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )736 ) < DBL_EPSILON )
#define kIPhone6Plus        (([UIScreen mainScreen].bounds.size.width == 414) ? YES : NO)

#define KIsiPhoneX ([UIDevice isiPhoneX])

//([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)



//是不是ios7及以上
#define iOS7  ( [[[UIDevice currentDevice] systemVersion] floatValue]>=7.0 )
#define iOS8  ( [[[UIDevice currentDevice] systemVersion] floatValue]>=8.0 )
#define iOS9  ( [[[UIDevice currentDevice] systemVersion] floatValue]>=9.0 )
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size)) : NO)

#define iPhone6plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)) : NO)

#define ISPAD      [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad

#define SCALE_X         ([UIScreen mainScreen].bounds.width/320.0f)

#ifndef weakify
#if DEBUG
#if __has_feature(objc_arc)
#define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;
#endif
#else
#if __has_feature(objc_arc)
#define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;
#endif
#endif
#endif

#ifndef strongify
#if DEBUG
#if __has_feature(objc_arc)
#define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;
#endif
#else
#if __has_feature(objc_arc)
#define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;
#endif
#endif
#endif

#define kErrorCodeForResponseIsNil -10000

#define kBtnCornerRadius 3
#define kImageBorderColor YICOLOR(@"#c9c9c9").CGColor
#define kLogoWidth 43
#define kCellPadding 10
#define kTextPadding (25/3.0f)
#define kDefalutImageRatio (2.0f/3)
#define kHalfButtonWidth 130
#define kCellGap (36/3.0f)
#define WHITE [UIColor whiteColor]
#define BLACK [UIColor blackColor]
#define RED [UIColor redColor]
#define kUndefineWeight (-1)
#define kStableMin 1

//#ifdef NSLocalizedString
//#undef NSLocalizedString
//#endif
//
//#define NSLocalizedString(key, strcomment) \
//[GET_COMPONENT(YILanguageMgr) localizedString:(key) comment:(strcomment)]
//#endif

#define WEAK_REF(obj) \
__weak typeof(obj) weak_##obj = obj;

#define IOS9 ([[UIDevice currentDevice] systemVersion].floatValue>=9)

//#define kLang(key) ([GET_COMPONENT(YILanguageMgr) localizedString:(key) comment:nil])
#define kImageView(key) [[UIImageView alloc] initWithImage:[UIImage imageNamed:key]]

#define RACViewObserve(TARGET, KEYPATH) \
[(id)(TARGET) rac_valuesForKeyPath:@keypath(TARGET, KEYPATH) observer:self.view]


#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

// 屏幕高度自适应(ipone6)
#define kAdpatHeight(value) (value * kScreenHeight / (kScreenHeight != 667.0f ? 667.0f : kScreenHeight))

// 屏幕宽度自适应(ipone6)
#define kAdpatWidth(value) (value * kScreenWidth / (kScreenWidth != 375.0f ? 375.0f : kScreenWidth))

// 屏幕高度自适应(ipone5)
#define kAdpatHeightIpone5(value) (value * kScreenHeight / (kScreenHeight != 568.0f ? 568.0f : kScreenHeight))

// 屏幕宽度自适应(ipone5)
#define kAdpatWidthIpone5(value) (value * kScreenWidth / (kScreenWidth != 320.0f ? 320.0f : kScreenWidth))

//权限标示
#define kOrderFlag @"order"
#define kPackageFlag @"send"

//获取系统版本
#define kIOSVersion [[[UIDevice currentDevice] systemVersion] floatValue]

// 获取应用版本
#define kBundleVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

//获取当前语言
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

//获取appdelegate
#define kAppDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)

// 检查是否为nil，为nil则返回空字符串对象
//#define kCheckNil(obj) ((obj) ? (obj) : (@""))
#define kCheckNil(value)\
({id tmp;\
if ([(value) isKindOfClass:[NSNull class]] || \
[[NSString stringWithFormat:@"%@",value] isEqualToString:@"(null)"] || \
[[NSString stringWithFormat:@"%@",value] isEqualToString:@"(NULL)"] || \
[[NSString stringWithFormat:@"%@",value] isEqualToString:@"null"] || \
[[NSString stringWithFormat:@"%@",value] isEqualToString:@"NULL"]) \
{tmp = @"";}\
else\
{tmp = (value?value:@"");}\
tmp;\
})\

// 检查字符串是否合法
#define kCheckStringLegal(obj) ((obj) && [(obj) isKindOfClass:[NSString class]])

// 检查字符串是否为空
#define kCheckStringEmpty(string) (string.length > 0 && ![string isEqualToString:@"null"] && ![string isEqualToString:@"NULL"])

// NSUserDefaults快速调用
#define kDefaultsSetObjectForKey(object, key) [[NSUserDefaults standardUserDefaults] setObject:object forKey:key]
#define kDefaultsGetObJectForKey(key) [[NSUserDefaults standardUserDefaults] objectForKey:key]
#define kDefaultsRemoveObjectForKey(key) [[NSUserDefaults standardUserDefaults] removeObjectForKey:key]

// 对象转字符串
#define kStringWithObject(object) [NSString stringWithFormat:@"%@",object]

// 获取单行label的Size
#define kGetSizeForLabel(label) [[label text] sizeWithAttributes:@{NSFontAttributeName:[label font]}]

#endif /* PublicDefine_h */



